package ciyuanwutuobang.threadagainstdeath;

import org.bukkit.Bukkit;

import java.util.Timer;
import java.util.TimerTask;

public class TPSCheck {

    public static long ServerTime = System.currentTimeMillis();
    public static int ServerTick = 0;
    public static int CurrentTPS = 20;

    private final ThreadAgainstDeath threadAgainstDeath;

    public TPSCheck(ThreadAgainstDeath threadAgainstDeath) {
        this.threadAgainstDeath = threadAgainstDeath;
        this.runTPSCheck();
    }

    private void runTPSCheck(){
        Bukkit.getScheduler().runTaskTimer(threadAgainstDeath, () -> {
            ServerTime = System.currentTimeMillis();
            ServerTick++;
        }, 0L, 1L);

        new Timer().scheduleAtFixedRate(new TimerTask(){
            @Override
            public void run(){
                CurrentTPS = ServerTick;
                ServerTick = 0;
            }
        }, 0L, 1000L);
    }
}
